package net.zdreamer.geracomium.ui.more;

import net.zdreamer.geracomium.adapter.MessageNotifiAdapter;
import net.zdreamer.geracomium.entity.MessageNotiInfos;
import net.zdreamer.geracomium.ui.BaseActivity;
import android.os.Handler;
import android.os.Message;
import android.text.format.DateUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ListView;

import com.example.geracomium.R;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;

public class PersonAsseReportActivity extends BaseActivity implements OnClickListener{
	private ImageView back, share;
	private PullToRefreshListView mPullRefreshListView;
	private MessageNotifiAdapter mAdapter;

	@Override
	protected int getContentView() {
		return R.layout.activity_asserepot;
	}

	@Override
	protected void init() {
		
		mPullRefreshListView = (PullToRefreshListView) findViewById(R.id.report_list);
	}

	@Override
	protected void initViews() {
		mPullRefreshListView.setMode(Mode.BOTH);
		MessageNotiInfos msgnoti = new MessageNotiInfos();
		mAdapter = new MessageNotifiAdapter(this, msgnoti.messagenotiInfos,
				R.layout.list_item);
		mPullRefreshListView.setAdapter(mAdapter);
		mPullRefreshListView.setOnRefreshListener(orl);
		ListView actualListView = mPullRefreshListView.getRefreshableView();
	}

	@Override
	protected void initListener() {
		findViewById(R.id.back).setOnClickListener(this);
	}

	private OnRefreshListener<ListView> orl = new OnRefreshListener<ListView>() {

		@Override
		public void onRefresh(PullToRefreshBase<ListView> refreshView) {
			String label = DateUtils.formatDateTime(getApplicationContext(),
					System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME
							| DateUtils.FORMAT_SHOW_DATE
							| DateUtils.FORMAT_ABBREV_ALL);

			refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(
					"上次刷新：" + label);

			Thread a = new Thread(new Runnable() {
				@Override
				public void run() {
					try {
						Thread.sleep(2000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					Message message = new Message();
					message.what = 0;
					h.sendMessage(message);
				}
			});
			a.start();
		}
	};
	Handler h = new Handler() {

		@Override
		public void handleMessage(Message msg) {
			if (msg.what == 0) {
				MessageNotiInfos msgnoti = new MessageNotiInfos();
				mAdapter = new MessageNotifiAdapter(
						PersonAsseReportActivity.this,
						msgnoti.messagenotiInfos, R.layout.list_item);
				mPullRefreshListView.setAdapter(mAdapter);
				mPullRefreshListView.onRefreshComplete();
			}
		}

	};

	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.back:
			PersonAsseReportActivity.this.finish();
			break;
			default:
				break;
		}
	}
}
